<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>default (Fusioncharts::DbJsController)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File app/controllers/fusioncharts/db_js_controller.rb, line 15</span>
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span>
    <span class="ruby-identifier">headers</span>[<span class="ruby-value str">&quot;content-type&quot;</span>]=<span class="ruby-value str">&quot;text/html&quot;</span>;
    <span class="ruby-ivar">@factory_data</span> = [] 
    <span class="ruby-ivar">@js_var_string</span> =<span class="ruby-value str">&quot;&quot;</span>
    <span class="ruby-identifier">index_count</span> = <span class="ruby-value">-1</span>
    <span class="ruby-comment cmt">#Get data from factory masters table</span>
    <span class="ruby-identifier">factory_masters</span> = <span class="ruby-constant">Fusioncharts</span><span class="ruby-operator">::</span><span class="ruby-constant">FactoryMaster</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>)
      <span class="ruby-identifier">factory_masters</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">factory_master</span><span class="ruby-operator">|</span> 
        <span class="ruby-identifier">total</span>=<span class="ruby-value">0</span><span class="ruby-value">.0</span>
        <span class="ruby-identifier">index_count</span> = <span class="ruby-identifier">index_count</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
        <span class="ruby-identifier">factory_id</span> = <span class="ruby-identifier">factory_master</span>.<span class="ruby-identifier">id</span>
        <span class="ruby-identifier">factory_name</span> = <span class="ruby-identifier">factory_master</span>.<span class="ruby-identifier">name</span>
        <span class="ruby-comment cmt"># Construct the javascript variable to hold an array.</span>
        <span class="ruby-ivar">@js_var_string</span> =<span class="ruby-ivar">@js_var_string</span><span class="ruby-operator">+</span> <span class="ruby-value str">&quot;data[&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">index_count</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;] = new Array();\n&quot;</span> ; 

        <span class="ruby-identifier">factory_master</span>.<span class="ruby-identifier">factory_output_quantities</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">factory_output</span><span class="ruby-operator">|</span>
                      <span class="ruby-identifier">date_of_production</span> = <span class="ruby-identifier">factory_output</span>.<span class="ruby-identifier">date_pro</span>
                      <span class="ruby-comment cmt"># Formats the date to dd/mm without leading zeroes</span>
                      <span class="ruby-identifier">formatted_date</span> = <span class="ruby-identifier">format_date_remove_zeroes</span>(<span class="ruby-identifier">date_of_production</span>)
                      <span class="ruby-identifier">quantity_number</span> = <span class="ruby-identifier">factory_output</span>.<span class="ruby-identifier">quantity</span>
                      <span class="ruby-comment cmt"># Calculate the total quantity for this factory</span>
                      <span class="ruby-identifier">total</span> = <span class="ruby-identifier">total</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">factory_output</span>.<span class="ruby-identifier">quantity</span>
                      <span class="ruby-comment cmt"># Append values to the javascript array</span>
                      <span class="ruby-ivar">@js_var_string</span> =<span class="ruby-ivar">@js_var_string</span><span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\t\t\t\tdata[&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">index_count</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;].push(new Array('&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">formatted_date</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;','&quot;</span> <span class="ruby-operator">+</span><span class="ruby-identifier">quantity_number</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">&quot;'));\n&quot;</span> 
                    <span class="ruby-keyword kw">end</span>
        <span class="ruby-comment cmt">#Formatting the output html</span>
        <span class="ruby-ivar">@js_var_string</span> =<span class="ruby-ivar">@js_var_string</span><span class="ruby-operator">+</span><span class="ruby-value str">&quot;\t\t\t&quot;</span>;
        <span class="ruby-comment cmt">#Push hash of values into the array          </span>
        <span class="ruby-ivar">@factory_data</span><span class="ruby-operator">&lt;&lt;</span>{<span class="ruby-identifier">:factory_index=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">index_count</span>,<span class="ruby-identifier">:factory_name=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">factory_name</span>,<span class="ruby-identifier">:factory_output=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">total</span>}
      <span class="ruby-keyword kw">end</span>
  <span class="ruby-keyword kw">end</span></pre>
</body>
</html>